<?php
/**
 * 标签模型
 * ============================================================================
 * 版权所有 2017 福建华晟网络科技，并保留所有权利。
 * 网站地址: http://www.fldcms.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: fld
 * Date: 2017-07-01
 */
namespace app\common\model;
class TagModel extends BaseModel {
	private $table_name = 'tag';
	
	/**
	 * 获取标签列表 分页
	 * @param unknown $result
	 */
	public function getTagList($result){
		$order = "id desc";
		$list = $this->select_table_by_page($this->table_name,$result['condition'],'*',$order,$result['query']);
		return $list;
	}
	/**
	 * 获取标签列表，无分页
	 */
	public function getList($condition=array()){
	    return $this->select_table($this->table_name,$condition,'*','id asc');
	}
	/**
	 * 获取标签列表，去除条件标签
	 */
	public function getRemoveList($tag_list){
		$list = $this->select_table($this->table_name,array(),'*','id asc');
		$result = array();
		$i = 0;
		foreach ($list as $k=>$v){
			$flag = true;
			foreach ($tag_list as $tk=>$tv){
				if($tv['id'] == $v['id']){
					$flag = false;
				}
			}
			if($flag){
				$result[$i] = $v;
				$i++;
			}
		}
		return $result;
	}
	/**
	 * 添加标签
	 */
	public function addData(){
		$data = array();
    	$data['tag_name'] = input('post.tag_name');
    	$data['update_time'] = time();
		$res = $this->insertData($data);
		if($res !== false){
			model('ActionLog')->action_log("添加","添加标签成功，标签编号=".$res."，标签名称=".input('post.tag_name'));
			return $res;
		}else{
			return false;
		}
	}
	/**
	 * 添加标签
	 */
	public function insertData($data){
	    return $this->add_table($this->table_name,$data,0);
	}
    /**
     * 获取单个标签信息
     * @param unknown $condition
     */
	public function getTagInfo($condition){
		return $this->find_table($this->table_name,$condition);
	}
	/**
	 * 更新标签信息
	 */
	public function updateData(){
		$id = input('post.id');
		$data['tag_name'] = input('post.tag_name');
		$res = $this->update_table($this->table_name,array('id'=>$id),$data,1);
		if($res !== false){
			model('ActionLog')->action_log("编辑","编辑标签成功，标签编号=".$id);
			return $res;
		}else{
			return false;
		}
	}
	/**
	 * 删除标签信息
	 */
	public function deleteData(){
		$id = input('param.id');
		$tag_info = $this->find_table($this->table_name,array('id'=>$id),'id,tag_name');
		$res = $this->delete_table($this->table_name,array('id'=>$id));
		if($res !== false){
			model('ActionLog')->action_log("删除","删除标签成功，标签编号=".$cate_info['id']."，标签账号=".$cate_info['cate_name']);
			return $res;
		}else{
			return false;
		}
	}
}
